#linux@linux-vir--mac:~/CProject/makefile/usecase$ make
#./src
#/home/linux/CProject/makefile/usecase/obj
#./src/add.c ./src/sub.c ./src/test.c
#/home/linux/CProject/makefile/usecase/obj/add.o /home/linux/CProject/makefile/usecase/obj/sub.o /home/linux/CProject/makefile/usecase/obj/test.o
#begin.......
#make -C src
#make[1]: 进入目录“/home/linux/CProject/makefile/usecase/src”
#gcc -c -g -Wall -I /home/linux/CProject/makefile/usecase/include/ add.c -o /home/linux/CProject/makefile/usecase/obj/add.o
#gcc -c -g -Wall -I /home/linux/CProject/makefile/usecase/include/ sub.c -o /home/linux/CProject/makefile/usecase/obj/sub.o
#gcc -c -g -Wall -I /home/linux/CProject/makefile/usecase/include/ test.c -o /home/linux/CProject/makefile/usecase/obj/test.o
#make[1]: 离开目录“/home/linux/CProject/makefile/usecase/src”
#gcc /home/linux/CProject/makefile/usecase/obj/add.o /home/linux/CProject/makefile/usecase/obj/sub.o /home/linux/CProject/makefile/usecase/obj/test.o -o test

#分目录管理源码
# *.c -> src
# *.o -> obj

SRCDIR = ./src
OBJDIR = $(shell pwd)/obj

SRC = $(wildcard $(SRCDIR)/*.c)
OBJ = $(patsubst %.c, $(OBJDIR)/%.o, $(notdir $(SRC)))

CC = gcc
CFLAGS = -c -g -Wall -I /home/linux/CProject/makefile/usecase/include/

export CC CFLAGS  OBJ OBJDIR

all:$(SRCDIR) test

$(SRCDIR):ECHO
	make -C $@

ECHO:
	@echo $(SRCDIR)
	@echo $(OBJDIR)
	@echo $(SRC)
	@echo $(OBJ)
	@echo "begin......."

test:$(OBJ)
	$(CC) $^ -o $@

clean:
	$(RM) *.o
